package com.sunfeng.n3;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * LockSupport
 *
 * @author sunfeng
 * @date 2021/03/16 17:26
 **/

@Slf4j(topic = "c.Test14")
public class Test14 {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {

            log.debug("park.....");
            LockSupport.park();
            log.debug("unpack....");

            //log.debug("打断状态为,{}", Thread.interrupted()); // 这个会把打断状态设置为false    LockSupport.park();  不失效
            log.debug("打断状态为,{}", Thread.currentThread().isInterrupted()); // 不会将打断状态设置为false    LockSupport.park();  失效
            LockSupport.park();
            log.debug("unpack....");
        }, "t1");

        t1.start();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //  打断状态为,true       LockSupport.park();失效
        t1.interrupt();
        //  LockSupport.unpark(t1);


    }
}
